package xin.clips.web.controller.gy;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import xin.clips.common.annotation.VisistLog;
import xin.clips.common.core.controller.BaseController;
import xin.clips.common.core.domain.AjaxResult;
import xin.clips.common.core.page.TableDataInfo;
import xin.clips.system.domain.gy.GyWorkOrder;
import xin.clips.system.service.gy.IGyInnerMessageService;
import xin.clips.system.service.gy.IGyWorkOrderService;
import java.util.List;

/**
 * 工单审核Controller
 *
 * @author clips
 * @date 2023-03-10
 */
@Controller
@RequestMapping("/gy/workOrderAudit")
public class GyWorkOrderAuditController extends BaseController {
    private String prefix = "gy/workOrderAudit";

    @Autowired
    private IGyWorkOrderService gyWorkOrderService;

    @Autowired
    private IGyInnerMessageService innerMessageService;

    @RequiresPermissions("gy:workOrderAudit:view")
    @VisistLog(title = "工单审核")
    @GetMapping()
    public String workOrder() {
        return prefix + "/workOrderAudit";
    }

    /**
     * 查询工单审核列表
     */
    @RequiresPermissions("gy:workOrderAudit:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GyWorkOrder gyWorkOrder) {
        startPage();
        List<GyWorkOrder> list = gyWorkOrderService.selectAuditWorkOrderList(gyWorkOrder);
        return getDataTable(list);
    }

    @RequiresPermissions("gy:workOrderAudit:audit")
    @GetMapping("/edit/{workId}")
    public String edit(@PathVariable("workId") Long workId, ModelMap mmap) {
        GyWorkOrder workOrder = gyWorkOrderService.selectGyWorkOrderByWorkId(workId);
        mmap.put("workOrder", workOrder);
        return prefix + "/edit";
    }

    /**
     * 更新申请完成工单信息
     */
    @RequiresPermissions("gy:workOrderAudit:audit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GyWorkOrder gyWorkOrder) {
        return AjaxResult.success(gyWorkOrderService.updateGyWorkOrderFinsh(gyWorkOrder));
    }

    /**
     * 修改保存人才认定申请业务
     */
    @RequiresPermissions("gy:workOrderAudit:audit")
    @PostMapping("/pass")
    @ResponseBody
    public AjaxResult pass(GyWorkOrder gyWorkOrder) {
        return AjaxResult.success(gyWorkOrderService.pass(gyWorkOrder));
    }

    /**
     * 修改保存人才认定申请业务
     */
    @RequiresPermissions("gy:workOrderAudit:audit")
    @PostMapping("/notPass")
    @ResponseBody
    public AjaxResult notPass(GyWorkOrder gyWorkOrder) {
        return AjaxResult.success(gyWorkOrderService.notpass(gyWorkOrder));
    }


    /**
     * 审核详情
     */
    @GetMapping("/detail")
    public String detail(@RequestParam("workId") String workId, ModelMap mmap) {
        GyWorkOrder workOrder= gyWorkOrderService.selectGyWorkOrderByWorkId(Long.valueOf(workId));
        mmap.put("workOrder", workOrder);
        return prefix + "/detail";
    }
}
